/** @file sdio.h
  *
  * @brief This file contains the function prototypes and definitions for
  * SDIO related functions of Bluetooth driver.
  * 
  * (c) Copyright 2003-2007, Marvell International Ltd.
  * All Rights Reserved
  */

#ifdef IF_SDIO

#ifndef _SDIO_H_
#define _SDIO_H_

#include "If.h"

//=============================================================================
//                                DEFINITIONS
//=============================================================================
#define MRVL_8100_SDIO_VER_ID               0x02

// Time to wait in ms to check FW again if it is not ready
#define SDIO_FW_NOT_READY_WAIT_TIME         5

#define SDIO_IO_READY                       0x08
#define SDIO_CIS_CARD_READY                 0x04
#define SDIO_UPLOAD_CARD_READY              0x02
#define SDIO_DOWNLOAD_CARD_READY            0x01
#define SDIO_IO_PORT                        0x10000

#ifdef PWARE_SDIO_INTR_MODIFICATIONS
#define SDIO_DISABLE_INTERRUPT_MASK         0x01
#define SDIO_ENABLE_INTERRUPT_MASK          0x00
#else
#define SDIO_DISABLE_INTERRUPT              0x0
#define SDIO_ENABLE_INTERRUPT               0x1
#endif

#define UPLOAD_HOST_INT_STATUS_RDY          0x01
#define DOWNLOAD_HOST_INT_STATUS_RDY        0x02
#define UPLOADDOWNLOAD_HOST_INT_STATUS_RDY  0x03 

// Internal Driver Trigger Event
#define MRVL_SOFT_INT_ChipReset             (1<<0)
#define MRVL_SOFT_INT_ExitThread            (1<<1)
#define MRVL_SOFT_INT_AutoDeepSleep         (1<<2)


// Host Control Register
#define HCR_HOST_INT_STATUS_REGISTER        0x5
#define HCR_HOST_INT_STATUS_RSR_REGISTER    0x6
#define HCR_HOST_INT_MASK_REGISTER          0x4
#define HCR_HOST_CONFIGURATION_REGISTER     0x3
#define HCR_SDIO_BUS_INTERFACE_CONTROL      0x7
#define HCR_HOST_CARD_STATUS_REGISTER       0x20

#define CARD_REVISION_REG                   0x3c

// Card Control Register
#define CCR_CARD_STATUS_REGISTER            0x20

// Scratch Register for Data Length
#define LENGTH_SCRATCH_REGISTER                0x34
#define PACKET_TYPE_MAC_EVENT_SCRATCH_REGISTER 0x36

#define CARD_OCR_0_REG                      0x34
#define CARD_OCR_1_REG                      0x35
#define CARD_OCR_3_REG                      0x36


// Code in the Scratch Register after FW is initialized
#define SDIO_FW_INIT_CODE                   0xFEDC

// Timer Counter used in Firmware Downloading
#define PKT_WAIT_TIME                       50000   // number of 10 us units

/* define SD block size for data Tx/Rx */
#if defined(HOST_MX31)
#define SDIO_EXTENDED_IO_BLOCK_SIZE         64
#else
#define SDIO_EXTENDED_IO_BLOCK_SIZE         32
#endif

/* define SD block size for firmware download */
#define SDIO_FW_DOWNLOAD_BLOCK_SIZE         512

#define SDIO_HEADER_LEN                     4


typedef enum _IF_FW_STATUS {
    FW_STATUS_READ_FAILED,
    FW_STATUS_INITIALIZED,
    FW_STATUS_UNINITIALIZED
} IF_FW_STATUS;

typedef enum _IF_API_STATUS {
    IF_SUCCESS = 0,
    IF_FAIL = 1,
} IF_API_STATUS;

#define IF_IS_SUCCESS(x)        ((x) == IF_SUCCESS)

typedef enum if_pkt_type {
    IF_DATA_PKT = 0,
    IF_CMD_PKT,
    IF_TX_DONE_EVENT,
    IF_MAC_EVENT,
    IF_INVALID_PKT_TYPE
} IF_PKT_TYPE;


//=============================================================================
//                          PUBLIC TYPE DEFINITIONS
//=============================================================================

//=============================================================================
//                          FUNCTION HEADER
//=============================================================================

MRVL_STATUS SDIOInitialization(PMRVDRV_ADAPTER pAdapter, UCHAR Function);
MRVL_STATUS sdio_Initialization(PMRVDRV_ADAPTER Adapter, UCHAR Function);
IF_API_STATUS sdio_ReadScratch(PMRVDRV_ADAPTER Adapter, UCHAR func, USHORT *pLength);
IF_API_STATUS sdio_GetDataBlock(PMRVDRV_ADAPTER Adapter, USHORT usLength, UCHAR *pPacket);
IF_API_STATUS sdio_ReInitCard(PMRVDRV_ADAPTER Adapter); 
#if MRVL_MONOLITHIC_SDIO
VOID sdio_ProcessSlotStatusChange(PMRVDRV_ADAPTER Adapter);
#endif
VOID sdio_DisableInterrupt(PMRVDRV_ADAPTER Adapter);
VOID sdio_EnableInterrupt(PMRVDRV_ADAPTER Adapter);
IF_API_STATUS sdio_PowerUpDevice(PMRVDRV_ADAPTER Adapter, UCHAR function);
IF_API_STATUS sdio_ClearPowerUpBit(PMRVDRV_ADAPTER Adapter, UCHAR function);

#endif // _SDIO_H_

#endif // IF_SDIO
